home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / bserverdir / sources / clients / life.c < prev    next >
C/C++ Source or Header  |  1994-11-29  |  4KB  |  154 lines

  1. ;/*
  2. sc Life.c DATA=FAR NMINC STRMERGE NOSTKCHK IGNORE=73 STRUCTUREEQUIVALENCE NOSTDIO
  3. slink from LIB:c.o Life.o to //Clients/Life LIB LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD NOICONS STRIPDEBUG
  4. delete life.o
  5. quit
  6.  
  7.  Life 1.2  (Client for BServer)
  8.  
  9.  Copyright © 1994 by Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/execbase.h>
  15. #include <exec/memory.h>
  16. #include <intuition/intuition.h>
  17.  
  18. #include <clib/exec_protos.h>
  19. #include <clib/intuition_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/alib_protos.h>
  22. /*#include <stdlib.h>*/
  23. #include <string.h>
  24. #include <time.h>
  25.  
  26. #include "/include/client.h"
  27. #include "/include/bitmap/bitmap.h"
  28. #include "/include/bitmap/bitmap_pragmas.h"
  29.  
  30. struct IntuitionBase *IntuitionBase;
  31. struct GfxBase *GfxBase;
  32. struct Library *BitMapBase;
  33.  
  34. struct DisplayIDInformation *dinfo;
  35.  
  36. struct Screen *scr;
  37. ULONG *ctptable;
  38. struct BitMap *bitmap;
  39.  
  40. extern ULONG RangeSeed;
  41. extern struct ExecBase *SysBase;
  42.  
  43. void Life( void )
  44. {
  45. UWORD swidth, sheight, xoffs, yoffs;
  46. struct Rectangle *rect;
  47. UBYTE *table1, *table2, *addr1, *addr2, adj;
  48. BOOL twenty_or_better = SysBase->AttnFlags & AFF_68020;
  49. BOOL success = FALSE;
  50.  
  51. rect = GETSTANDARDRECT(dinfo);
  52.  
  53. swidth = RECTANGLEWIDTH(rect);
  54. sheight = RECTANGLEHEIGHT(rect);
  55.  
  56. if ( scr = OpenScreenTags( NULL,
  57.     SA_DisplayID, DISPLAYID( dinfo ),
  58.     SA_Width, swidth,
  59.     SA_Height, sheight,
  60.     SA_Depth, 1,
  61.     SA_Quiet, TRUE,
  62.     TAG_END ) )
  63.     {
  64.     xoffs = (swidth - 320)/2;
  65.     yoffs = (sheight - 200)/2;
  66.     bitmap = scr->RastPort.BitMap;
  67.  
  68.     if ( table1 = AllocVec( 64000, MEMF_ANY | MEMF_CLEAR ) )
  69.         {
  70.         if ( table2 = AllocVec( 64000, MEMF_ANY | MEMF_CLEAR ) )
  71.             {
  72.             if ( ctptable = CreateCTPTable( bitmap ) )
  73.                 {
  74.                 UWORD n;
  75.                 struct ViewPort *vp = &(scr->ViewPort);
  76.  
  77.                 success = TRUE;
  78.                 SpritesOff();
  79.  
  80.                 SetRGB4( vp, 0, 0, 0, 0 );
  81.                 SetRGB4( vp, 1, 6, 6, 6 );
  82.  
  83.                 SetAPen( &scr->RastPort, 1 );
  84.  
  85.                 for ( n = 0; n < 64000; n++ )
  86.                     *(table1+n) = RangeRand( 2 );
  87.  
  88.                 while( STILL_BLANKING )
  89.                     {
  90.                     UWORD rows, columns;
  91.                     UBYTE *tmp;
  92.  
  93.                     memset( table2, 0, 64000 );
  94.  
  95.                     addr1 = table1 + 321;
  96.                     addr2 = table2 + 321;
  97.                     for ( rows = 0; rows < 198; rows++ )
  98.                         {
  99.                         for ( columns = 0; columns < 318; columns++ )
  100.                             {
  101.                             adj = *(addr1-321) + *(addr1-320) + *(addr1-319) + *(addr1-1) + *addr1 + *(addr1+1) + *(addr1+319) + *(addr1+320) + *(addr1+321);
  102.                             if ( adj == 3 )
  103.                                 *(addr2) = 1;
  104.                             if ( adj == 4 )
  105.                                 *(addr2) = *(addr1);
  106.                             addr1++;
  107.                             addr2++;
  108.                             if ( !twenty_or_better )
  109.                                 ChunkyToPlanar( bitmap, xoffs + columns, yoffs + rows, adj == 3, ctptable );
  110.                             }
  111.                         addr1 += 2;
  112.                         addr2 += 2;
  113.                         }
  114.                     if ( twenty_or_better )
  115.                         ChunkyToPlanarArray68020( bitmap, xoffs, yoffs, table2, ctptable, 320, 200, 320 );
  116.                     tmp = table1; table1 = table2; table2 = tmp;
  117.                     }
  118.                 SpritesOn();
  119.                 FreeCTPTable( ctptable, bitmap );
  120.                 }
  121.             FreeVec( table2 );
  122.             }
  123.         FreeVec( table1 );
  124.         }
  125.     CloseScreen( scr );
  126.     }
  127.  
  128. if ( !success )
  129.     SendClientMsg( ACTION_FAILED );
  130. }
  131.  
  132. void __main( char *line )
  133. {
  134. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  135.     {
  136.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  137.         {
  138.         if ( BitMapBase = OpenLibrary( "bitmap.library", 0L ) )
  139.             {
  140.             if ( dinfo = OpenCommunication() )
  141.                 {
  142.                 RangeSeed = time( NULL );
  143.  
  144.                 Life();
  145.                 CloseCommunication( dinfo );
  146.                 }
  147.             CloseLibrary( BitMapBase );
  148.             }
  149.         CloseLibrary( (struct Library *)GfxBase );
  150.         }
  151.     CloseLibrary( (struct Library *)IntuitionBase );
  152.     }
  153. }
  154.